From Cppreference
|
|
template< class Function, class... Args>
std::future<typename std::result_of<Function(Args...)>::type>
async( Function&& f, Args&&... args );
|
(1)
|
(since C++11)
|
|
|
|
template< class Function, class... Args >
std::future<typename std::result_of<Function(Args...)>::type>
async( std::launch policy, Function&& f, Args&&... args );
|
(2)
|
(since C++11)
|
|
|
|
[edit] Parameters
| f
|
-
|
function to call
|
| args...
|
-
|
parameters to pass to f
|
| policy
|
-
|
defines how to launch the function
|
[edit] Return value
std::future referring to the return value of the function.
[edit] Exceptions
[edit] Example
int parallel_sum(int* data, int size)
{
int sum = 0;
if ( size < 1000 )
for ( int i = 0; i < size; ++i )
sum += data[i];
else {
auto handle = std::async(parallel_sum, data+size/2, size-size/2);
sum += parallel_sum(data, size/2);
sum += handle.get();
}
return sum;
}